"""
按周期计算是否新高新低，简单方法
"""
class continue_updown:
    def __init__(self):
        self.timeperiod=2
        self.data=[]
        self.timekey = None
        self.fx=None
        self.n=0
    def oncalc(self,d,timekey=None):
        rst=None
        if d!=None:
            if timekey != None:
                if timekey == self.timekey:
                    self.data[-1] = d
                else:
                    self.data.append(d)
                    self.timekey = timekey
            else:
                self.data.append(d)
            if len(self.data)>self.timeperiod:
                self.data.pop(0)
            if len(self.data)==self.timeperiod:
                if self.fx=="up":
                    if self.data[0] > d:
                        self.fx = "down"
                        self.n = -1
                    else:
                        self.n=self.n+1
                elif self.fx=="down":
                    if self.data[0]<d:
                        self.fx="up"
                        self.n=1
                    else:
                        self.n=self.n-1
                else:
                    if self.data[0]<d:
                        self.fx="up"
                        self.n=1
                    elif self.data[0]>d:
                        self.fx = "down"
                        self.n = -1
        return self.n